package com.coco.seck.controller;

import com.coco.seck.pojo.TbSeckillGoods;
import com.coco.seck.service.SeckGoodsService;
import com.coco.seck.vo.SeckGoodsSearchVo;
import com.coco.seck.vo.SeckGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/7/18 15:23
 */
@RestController
@RequestMapping("/seck/goods")
public class SeckGoodsController {

    @Autowired(required = false)
    private SeckGoodsService goodsService;

    /**
     * 查询列表
     *
     * @param searchVo
     * @return
     */
    @PostMapping("/findSeckGoods")
    public List<SeckGoodsVo> findSeckGoods(@RequestBody SeckGoodsSearchVo searchVo) {
        return goodsService.findSeckGoods(searchVo);
    }

    /**
     * 修改商品状态
     */
    @GetMapping("/updateStatus/{id}/{status}")
    public void updateStatus(@PathVariable("id") Long id, @PathVariable("status") String status) {
        goodsService.updateStatus(id, status);
    }

    /**
     * 查询单条
     */
    @GetMapping("/findById/{id}")
    public TbSeckillGoods findById(@PathVariable("id") Long id) {
        return goodsService.findById(id);
    }

    /**
     * 删除商品
     */
    @DeleteMapping("/deleteSecGoods/{id}")
    public void deleteSecGoods(@PathVariable("id") Long id) {
        goodsService.deleteSeckGoods(id);
    }

    /**
     * 编辑商品信息
     */
    @PutMapping("/updateSeckGoods/{id}")
    public void updateSeckGoods(@PathVariable("id") Long id, @RequestBody TbSeckillGoods seckillGoods) {
        goodsService.updateSeckGoods(id, seckillGoods);
    }

    /**
     * 添加秒杀商品
     */
    @PostMapping("/addSeckGoods/{id}")
    public void addSeckGoods(@RequestBody List<TbSeckillGoods> goodsList, @PathVariable("id") Long id) {
        goodsService.addSeckGoods(goodsList, id);
    }
}
